<template>
<div>

  <el-breadcrumb separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>系统管理</el-breadcrumb-item>
    <el-breadcrumb-item>用户管理</el-breadcrumb-item>
  </el-breadcrumb>

  <el-card style="margin-top: 2%">
    <el-input style="width: 20%"
              placeholder="请输入姓名"
              v-model="user.username">
    </el-input>
    <el-input style="width: 20%"
              size="medium"
              placeholder="请输入账号"
              v-model="user.account">
    </el-input>
    <el-input style="width: 20%"
              size="medium"
              placeholder="请输入用户id"
              v-model="user.id">
    </el-input>
    <el-button type="primary">搜索</el-button>
    <el-button type="primary"@click="dialogVisible = true">添加</el-button>

    <hr style="border: 1px;background-color: red"/>
    <el-table :header-cell-style="{background:'darkcyan',color:'white'}"
      :data="user" :border="true"
      style="width: 100%;">
<!--      <el-table-column-->
<!--        label="id"-->
<!--        prop="id">-->

<!--      </el-table-column>-->

      <el-table-column label="姓名" prop="username">

      </el-table-column>

      <el-table-column label="账号" prop="useraccount">

      </el-table-column>
<!--      <el-table-column label="角色" prop="role"></el-table-column>-->
      <el-table-column label="电话" prop="phone"></el-table-column>
      <el-table-column label="详细地址" prop="detailAddress"></el-table-column>
      <el-table-column label="邮箱" prop="email"></el-table-column>
<!--      <el-table-column label="是否有效" prop="isAvlid"></el-table-column>-->
<!--      <el-table-column label="开始日期" prop="startdate"></el-table-column>-->
<!--      <el-table-column label="结束日期" prop="enddate"></el-table-column>-->
      <el-table-column label="头像" prop="photo"></el-table-column>

      <el-table-column label="操作" style="width: 20%">



        <template slot-scope="scope">
          <el-tooltip class="item" effect="light" content="编辑" placement="top-start">
          <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)"><i class="el-icon-edit"></i></el-button>  </el-tooltip>
            <el-tooltip class="item" effect="light" content="配置角色" placement="top-start">
          <el-button
            size="mini"
            @click="handleOpt(scope.$index, scope.row)"><i class="el-icon-share"></i></el-button> </el-tooltip>
              <el-tooltip class="item" effect="light" content="删除" placement="top-start">
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"><i class="el-icon-delete"></i></el-button> </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination style="margin-top: 15px"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="queryInfo.pagenum"
      :page-sizes="[1, 2, 5, 10]"
      :page-size="queryInfo.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totol">
    </el-pagination>

    <el-dialog
      title="添加用户"
      :visible.sync="dialogVisible"

      width="50%"

      style="height: 100%"
    center>

      <AddUser @closeDialog="handleclose"></AddUser>

    </el-dialog>

    <el-dialog
      title="角色配置"
      :visible.sync="dialogVisible1"

      width="20%"

      style="height: 100%"
      center>

      <el-form ref="user" v-model="user" label-width="80px" style="align-content: center">
        <el-form-item label="角色信息" prop="role">
          <el-select v-model="user.role" filterable multiple  placeholder="请选择需要配置的角色">
            <el-option
              v-for="item in options"
              :key="item.rolecode"
              :label="item.rolename"
              :value="item.rolecode">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item style="align-content: center">
          <el-button type="primary" @click="onSubmit">确定</el-button>
          <el-button @click="cancal">  取消</el-button>
        </el-form-item>
      </el-form>

    </el-dialog>

  </el-card>




</div>
</template>

<script>
import instance from "../../utils/request";
import AddUser from "./AddUser";
import {MessageBox} from "element-ui";
export default {
  name: "UserList",
  components: {AddUser},
  comments:{
    AddUser
  },
  data() {
    return {

      options:[{
        rolecode: '',
        rolename: ''
      }],
      dialogVisible: false,
      dialogVisible1: false,
      user:[{
        id:'',
        username:'',
        password:'',
        useraccount:'',
        role:''
      }],

      //获取用户列表的参数对象
      queryInfo:{
        query:'',
        pagenum:1,
        pageSize:2
      },
      totol:0,

      show:true,
    }
  },
  methods: {
    //修改密码提交事件
    onSubmit(){

    },
    cancal(){
      this.dialogVisible1 = false;
    },
    //点击角色配置时的角色数据获取
    getRoleData(){
      instance.get("/user/getrole").then(res=>{
        this.options = res.data.data;
      }).catch(err=>{
        MessageBox.alert("后台服务器错误");
      })
    },
    handleOpt(index,row){
      this.dialogVisible1 = true;
      this.getRoleData();
      console.log(index);
      console.log(row.username);
    },

    //监听pagesize改变的事件
    handleSizeChange(newSize){
      this.queryInfo.pageSize = newSize;
      this.getUserList();
      console.log(newSize);

    },

    //监听页码值改变的事件
    handleCurrentChange(newPage){
      this.queryInfo.pagenum = newPage;
      this.getUserList();

    },

    handleclose() {
      console.log(12345);
      this.dialogVisible = false;
    },

    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
    findPage(page){
      console.log(page);
    },
    findSize(size){
      console.log(size);
    },
    addUser(){
    },

    getUserList(){
      instance.get("/user/findByPage",{params:this.queryInfo}).then(res=>{
        this.user = res.data.list;
        this.totol = res.data.totol;
        return this.user;
      }).catch(err=>{
        alert("后台服务器错误");
      })
    },



  },


  created() {
    this.getUserList();
  }
}
</script>

<style>
.transition-box {
  margin-bottom: 10px;
  width: 200px;
  height: 100px;
  border-radius: 4px;
  background-color: #409EFF;
  text-align: center;
  color: #fff;
  padding: 40px 20px;
  box-sizing: border-box;
  margin-right: 20px;
}
</style>
